package com.kingsystem.kingteachermarks_backend.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kingsystem.kingteachermarks_backend.entity.SystemUser;
import com.kingsystem.kingteachermarks_backend.entity.ViewSystemUser;
import com.kingsystem.kingteachermarks_backend.mapper.SystemUserMapper;
import com.kingsystem.kingteachermarks_backend.mapper.ViewSystemUserMapper;
import com.kingsystem.kingteachermarks_backend.service.impl.ViewSystemUserServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author leiyue_yao
 * @since 2025-07-27
 */
@Controller
@RequestMapping("/viewSystemUser")
@CrossOrigin
public class ViewSystemUserController {

    @Autowired
    private ViewSystemUserMapper vsu;

    @Autowired
    private ViewSystemUserServiceImpl vsui;

    @PostMapping("/getUsers")
    @ResponseBody
    @ApiOperation(value="获取用户",notes="根据用户名获取用户信息")
    public List<ViewSystemUser> getUsers(@RequestParam("real_name") String real_name){
        real_name = real_name.trim();
        QueryWrapper<ViewSystemUser> wrapper = new QueryWrapper<>();
        wrapper.select("tablekey, real_name, title,diploma,dept_path")
                .like("real_name",real_name)
                .orderByAsc("real_name");//记住要进行排序，不然不能用



        IPage<ViewSystemUser> page_user = new Page<>(1, 10);
        vsu.selectPage(page_user,wrapper);

        List<ViewSystemUser> Li = page_user.getRecords();
//        List<ViewSystemUser> Li = vsu.selectList(wrapper);
        return Li;
    }
}
